// pages/index/index.js
const app = getApp();

Page({
  data: {},

  onLoad() {
    // 检查是否已登录
    if (app.globalData.userInfo) {
      this.redirectToHome();
    }
  },

  onShow() {
    // 检查登录状态
    if (app.globalData.userInfo) {
      this.redirectToHome();
    }
  },

  redirectToHome() {
    const userType = app.globalData.userType;

    if (userType === "student") {
      wx.switchTab({
        url: "/pages/student/profile/profile",
      });
    } else if (userType === "judge") {
      wx.navigateTo({
        url: "/pages/judge/dashboard/dashboard",
      });
    }
  },

  goToLogin() {
    wx.navigateTo({
      url: "/pages/login/login",
    });
  },
});
